/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ViewSchedulerInDep.java
 *
 * Created on Feb 10, 2012, 9:30:47 AM
 */
package ui.panels;

import entities.User;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;
import manager.DoctorDriver;
import model.ViewSchedulerDepTableModel;
import ui.windows.RemedySchedulerFrame;

/**
 *
 * @author viev
 */
public class ViewSchedulerInDep extends javax.swing.JPanel {

    /** Creates new form ViewSchedulerInDep */
    public ViewSchedulerInDep(RemedySchedulerFrame mainFrame) {
        this.mainFrame = mainFrame;
        driver = (DoctorDriver) mainFrame.getDriver();
        initComponents();
        includeModel();
    }
    
    private void includeModel() {
        User user = mainFrame.getUser();
        model = new ViewSchedulerDepTableModel(driver.showEShedulerInDep(user.getUserID(), user.getDepartmentID()));
        schedulerTable.setModel(model);  
        schedulerTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        
        schedulerTable.setFillsViewportHeight(true);
        schedulerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        schedulerTable.getTableHeader().setFont(new Font(null, Font.BOLD, 10));   
        DefaultTableCellRenderer cellRenderer1 = new DefaultTableCellRenderer();
        cellRenderer1.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
        cellRenderer1.setBackground(new Color(200, 200, 220));
        DefaultTableCellRenderer cellRenderer2 = new DefaultTableCellRenderer();
        cellRenderer2.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
        cellRenderer2.setBackground(new Color(100, 50, 102));
        cellRenderer2.setForeground(new Color(240, 240, 240));
        DefaultTableCellRenderer cellRenderer3 = new DefaultTableCellRenderer();
        cellRenderer3.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
        cellRenderer3.setBackground(Color.yellow);        
        schedulerTable.getColumnModel().getColumn(0).setPreferredWidth(100);
        schedulerTable.getColumnModel().getColumn(0).setCellRenderer(cellRenderer1);
        schedulerTable.getColumnModel().getColumn(1).setPreferredWidth(220);
        schedulerTable.getColumnModel().getColumn(1).setCellRenderer(cellRenderer1);
        schedulerTable.getColumnModel().getColumn(2).setPreferredWidth(180);
        schedulerTable.getColumnModel().getColumn(2).setCellRenderer(cellRenderer2);
        schedulerTable.getColumnModel().getColumn(3).setPreferredWidth(120);
        schedulerTable.getColumnModel().getColumn(3).setCellRenderer(cellRenderer3);
        schedulerTable.getColumnModel().getColumn(4).setPreferredWidth(120);
        schedulerTable.getColumnModel().getColumn(4).setCellRenderer(cellRenderer3);
    }
    
    private void filter() {
        String id = txtID.getText();
        String name = txtName.getText();
        model.filter(id, name, 0, 0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private RemedySchedulerFrame mainFrame;
    private DoctorDriver driver;
    private ViewSchedulerDepTableModel model;
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtID = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        viewScheduler = new javax.swing.JScrollPane();
        schedulerTable = new javax.swing.JTable();

        setBackground(new java.awt.Color(255, 255, 255));
        setLayout(new java.awt.BorderLayout());

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("ID:");

        txtID.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                txtIDCaretUpdate(evt);
            }
        });

        jLabel2.setText("Name:");

        txtName.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                txtNameCaretUpdate(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(313, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(jPanel1, java.awt.BorderLayout.PAGE_START);

        schedulerTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        viewScheduler.setViewportView(schedulerTable);

        add(viewScheduler, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

private void txtIDCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_txtIDCaretUpdate
    filter();
}//GEN-LAST:event_txtIDCaretUpdate

private void txtNameCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_txtNameCaretUpdate
    filter();
}//GEN-LAST:event_txtNameCaretUpdate

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTable schedulerTable;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtName;
    private javax.swing.JScrollPane viewScheduler;
    // End of variables declaration//GEN-END:variables
}
